import { changeTypeEnum, pointsTypeEnum, renderChangeType } from './enum';

export const columns = () => [
  {
    title: '积分变更原因',
    dataIndex: 'pointsType',
    valueType: 'select',
    fieldProps: {
      options: Object.keys(pointsTypeEnum).map((key) => ({
        label: pointsTypeEnum[key].text,
        value: parseInt(key),
      })),
    },
    hideInTable: true,
  },
  {
    title: '变更时间范围',
    dataIndex: 'startTime',
    hideInTable: true,
    valueType: 'dateRange',
    fieldProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
    },
    search: {
      transform: (value) => {
        return {
          startTime: value[0],
          endTime: value[1],
        };
      },
    },
  },
  {
    title: '积分变更类型',
    dataIndex: 'changeType',
    valueType: 'select',
    fieldProps: {
      options: Object.keys(changeTypeEnum).map((key) => ({
        label: changeTypeEnum[key].text,
        value: parseInt(key),
      })),
    },
    hideInTable: true,
  },
  {
    title: '积分变更原因',
    dataIndex: 'reason',
    hideInSearch: true,
    render: (_, record) => {
      return (
        <div>
          <span>{(record.pointsType && pointsTypeEnum[record.pointsType].text) || '-'}</span>
          {(record.pointsType === 2 || record.record === 6) && (
            <span>{`(订单编号：${record.businessId})`}</span>
          )}
        </div>
      );
    },
  },
  {
    title: '收入/支出',
    dataIndex: 'details',
    hideInSearch: true,
    render: (_, record) => renderChangeType[record.changeType] + record.changeNum,
  },
  {
    title: '积分余额',
    dataIndex: 'changeAfterNum',
    align: 'left',
    hideInSearch: true,
  },
  {
    title: '变更时间',
    dataIndex: 'createTime',
    align: 'left',
    hideInSearch: true,
  },
];
